/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.figures;

import org.eclipse.draw2d.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;

import com.cea.papyrus.core.PapyrusPlugin;

/**
 * A Figure with a bent corner and an embedded TextFlow within a FlowPage that contains
 * text.
 * 
 * @see org.eclipse.gef.examples.ediagram.figures.StockNoteFigure
 */
public class TaggedStickyNoteFigure extends StickyNoteFigure {
	
	/**
	 * label that displays the tag of the figure.
	 */
	protected Label tagLabel;
	
	/**
	 * Creates a new StickyNoteFigure with a default MarginBorder size of DEFAULT_CORNER_SIZE
	 * - 3 and a FlowPage containing a TextFlow with the style WORD_WRAP_SOFT.
	 * 
	 * @param keyword the tag of the element
	 */
	public TaggedStickyNoteFigure(String keyword) {
		this(BentCornerFigure.DEFAULT_CORNER_SIZE - 3, keyword);
	}

	/**
	 * Creates a new StickyNoteFigure with a MarginBorder that is the given size and a
	 * FlowPage containing a TextFlow with the style WORD_WRAP_SOFT.
	 * 
	 * @param keyword the tag of the element
	 * @param borderSize the size of the MarginBorder
	 */
	public TaggedStickyNoteFigure(int borderSize, String keyword) {
		super(borderSize);
		if (keyword != null) {
			this.createTagLabel(keyword);
		}
		
	}

	/**
	 * This method is used to create the tag label in the figure.
	 * 
	 * @param keyword 
	 */
	protected void createTagLabel(String keyword) {
		FontData[] fontdata={new FontData(this.fontString, this.fontSize, SWT.NORMAL)};
		Font font = PapyrusPlugin.fontManager.get(fontdata);
		Label label = new Label();
		label.setFont(font);
		label.setForegroundColor(this.fontColor);
		label.setOpaque(false);
		label.setText(PapyrusPlugin.ST_LEFT+keyword+PapyrusPlugin.ST_RIGHT);
		// Add the tag label to the figure at the position 0
		this.add(label, 0);
		this.tagLabel = label;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.figures.NodeFigure#getIconLabelPosition()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	protected int getIconLabelPosition() {
		return 1;
	}

}